//var bCCDebug=false;
function compareDate(DateOne,DateTwo)
{
	var startMonth = DateOne.substring(5,DateOne.lastIndexOf ("-"));	
	var startDay = DateOne.substring(DateOne.length,DateOne.lastIndexOf ("-")+1);
	var startYear = DateOne.substring(0,DateOne.indexOf ("-"));
	
	var endMonth = DateTwo.substring(5,DateTwo.lastIndexOf ("-"));
	var endDay = DateTwo.substring(DateTwo.length,DateTwo.lastIndexOf ("-")+1);
	var endYear = DateTwo.substring(0,DateTwo.indexOf ("-"));
	
	if (Date.parse(startMonth+"/"+startDay+"/"+startYear) <=
	Date.parse(endMonth+"/"+endDay+"/"+endYear))
	{	
		var str=[];
		if(parseInt(endYear)>parseInt(startYear)){
			var mins = endYear-startYear;
			for(var i = startYear;i<=endYear;i++){
				str[i-startYear] = i;
			}
		}
		if(parseInt(endMonth)>parseInt(startMonth)){
			var mins = endMonth-startMonth;
			for(var i = startMonth;i<=endMonth;i++){
				str[i-startMonth] = i;
			}
		}
		if(parseInt(endDay)>parseInt(startDay)){
			var mins = endDay-startDay;
			for(var i = startDay;i<=endDay;i++){
				str[i-startDay] = i;
			}
		}		
		if(parseInt(endDay)==parseInt(startDay)){
			var mins = endDay-startDay;
			for(var i = 1;i<=24;i++){
				str[i-1] = i;
			}
		}			
		//return Date.parse(startMonth+"/"+startDay+"/"+startYear)-Date.parse(endMonth+"/"+endDay+"/"+endYear)
		return str;
	}
	else
	{
		alert("终止时间应大于起始时间")
	}

}
var bCCDebug=true;
/*function onQuerySta(){
	alert("ggggg");
}*/
function CCDebug(nd){
	if(bCCDebug) 
		return nd;
	else return null;
}

function CM_slen4(n){
	var s0='0000';
	var s = ''+n;
	var len = s.length;
	return s0.substring(0,4-len)+s;
}
function getagh(code){
	var sbuf="";
	sbuf+="<span style=\"font-family:dpm\">&#";
	if (code.length==4)
		code="A"+code.substring(1);
	sbuf+=parseInt(code,16);						
	sbuf+="</span>";
	return sbuf;
}
function renderTabByStart(tab){
	var start = tab.start;
	if(tab.tb_rendered)
		return;
	var start = tab.start;
	var m=['<table class="x-date-inner" cellspacing="0"><thead><tr>'];
	for(var i=0; i<11; i++){
		if(i==0)
			m.push('<th><span></span></th>');
		else
			m.push('<th><span>0'+(i-1)+'</span></th>');
	}
	m[m.length] = "</tr></thead><tbody>";
	var pos=0;
	for(var i=0; i<10; i++){
		var si = start+pos;
		m[m.length]='<tr><th><span>'+CM_slen4(si)+'</span></th>';
		for(var j=0; j<10; j++){
			var code = si+j;
			var tacode = CM_slen4(code);
			m[m.length]='<td><a class="x-date-date" style="font-size:20px;"' 
			+' title="'+tacode
			+'">'+getagh(tacode)+'</a></td>';
			//+'"><img height=14 src ="../../dpm/strangeimg/'
			//+tacode+'.gif"/></a></td>';
			//TODO 
		}
		pos+=10;		
	}
	var tb = tab.body.createChild(m.join(''));
	tb.on("click", function(e,t){
		 e.stopEvent();
		 CC.DlgCharMapping.clipfield.setValue('『'+t.title+'』');
		 //alert(t.title);
	},  tb, {delegate: "a.x-date-date"});
	tab.tb_rendered=true;	
}
function onItemCheck(item, checked){
	if(!checked) return;
	Cookies.set('exttheme', item.value);
	setTimeout(function(){
		window.location.reload();
	}, 250);
}

function renderNodeEdit(node,nn){
	var filter;
	var vn=node.vn;
	if(!vn)
		vn=nn[node.fn];
	
	var id_tab = 'tabs_edit_'+node.id;
	var tabPanel = viewport.getComponent('center');
	var cd = tabPanel.getItem(id_tab);
	var title = node.getPath('text').substr(1);
	var t;
	if(!cd){
		var vw = Bat.cloneVW(vn);
		if(!vw) 
			return null;
		t=new Bat.UI.Ext({view:vw,vn:vn});
		var id_grid = id_tab+'_grid';
		cd = tabPanel.add({
			id:id_tab,
			title: title,
            iconCls: 'tabs',
           	closable:false,
			autoScroll: true,
            html:"<div id='"+id_grid+"' style='width:100%;height:100%;'/>"
 		});
		cd.show();
		var fm = t.renderEdit(id_grid);
		cd.ui = t;
	}else t = cd.ui;
	tabPanel.setActiveTab(id_tab);
	tabPanel.getActiveTab().setTitle(title);
	return t;		
}
function renderGridByNode(node,nn,vfunc){
	var vn=node.vn||node.attributes['vn'];
	
	var id_tab = 'tabs_grid_'+node.id;
	var tabPanel = viewport.getComponent('center');
	//var cd = tabPanel.getItem(id_tab);
	var cd = tabPanel.tabs[id_tab];
	var title = node.getPath('text').substr(1);
	var id_grid = id_tab+'_grid';
	var t;
	if(!cd){
		//modify view a little
		var vw = Bat.cloneVW(vn);
		if(!vw) 
			return null;
		if(vfunc)
			vw = vfunc(vw);
		t=new Bat.UI.Ext({view:vw});
		t.node=node;
		cd = tabPanel.add({
			id:id_tab,
			title: title,
            iconCls: 'tabs',
           	closable:true,
            autoDestroy: false,
			autoScroll: false,
            html:"<div id='"+id_grid+"' style='width:100%;height:100%;background-color:#D0DEF0'/>"
 		});
 		tabPanel.tabs[id_tab]=cd;
		cd.ui = t;
		cd.on('activate',function(p){
			CC.tbar.items.itemAt(1).setDisabled(true);
			CC.tbar.items.itemAt(2).setDisabled(true);
		});
		cd.show();
	}else{
		t = cd.ui;
		tabPanel.unhideTabStripItem(cd.show());
	}
	cd.bHide=false;
	t.render(id_grid);
	tabPanel.setActiveTab(id_tab);
	tabPanel.getActiveTab().setTitle(title);
	return t;
}
function buildNode(pn,nc){
	if(!pn || !nc)
	  return;
	var ntxt;
	if(typeof nc=='string')
	  nc = {fv:nc};
	ntxt = nc.txt || nc.fv;
	if(typeof nc=='string'){
		pn.appendChild(new Ext.tree.TreeNode({text:nc, 
			allowDrag:false,allowDrop:false}));
		return;
	}
  	var cn = new Ext.tree.TreeNode({text:ntxt, 
		allowDrag:false,allowDrop:false});
	cn.fv = nc.fv;
	pn.appendChild(cn);
 	for(y in nc){
  		if(y=='ns'){
  			var ns = nc[y];
  			for(var i=0; i<ns.length; i++){
  				buildNode(cn,ns[i]);
  			}  			
  		}else{
  			cn[y]=nc[y];
  		}
  	}
}
var viewport;
var CC = function(){
return {
	showPrjPro:function(btn,selid,prjrd){
	  var ui=btn.ui;
	  var dlg =CC.PrjPro; 
	   var me=this;
	  if(!dlg){
	    dlg = new Ext.Window({
			title		  :'项目进度',
	        layout      : 'fit',
	        width       : 400,
	        height      : 250,
	        closeAction :'hide',
	        plain       : true,
	        html:"<div >&nbsp;&nbsp;" +
	       "&nbsp;&nbsp;<br>" +
	       "<div id='divPrjPro'>"+prjrd+"" +
	       	"<br>&nbsp;&nbsp;<a href='/cc/servlet/DefaultExportExcelControl?prjid="+selid+">项目进度的详细统计结果（.xls）</a></div>"

	    });
		CC.PrjPro=dlg;
      }else{
  	    Ext.getDom("divPrjPro").innerHTML=""+prjrd+"" +
	       	"<br><br>&nbsp;&nbsp;<a href='/cc/servlet/DefaultExportExcelControl?prjid="+selid+"' target='_blank'> 项目进度的详细统计结果（.xls）</a>";
      }
	dlg.show();
	},
	showImgImport:function(btn){
	  var ui=btn.ui;
	  var dlg =CC.DlgImgImport; 
	   var me=this;
	  if(!dlg){
    dlg = new Ext.Window({
		title		  :'导入影像',
        layout      : 'fit',
        width       : 400,
        height      : 250,
        closeAction :'hide',
        plain       : true,
        html:"<div >&nbsp;&nbsp;<form id='uploadDbForm' action='"+Bat.WC+"servlet/fudb' method='POST' enctype='multipart/form-data' target='bat_iframehide'>" +
       "<table ><tr><td><label class='x-form-item'>&nbsp;请选择待上传文件：</label></td><td><input type='file' name='filename' class='x-form-file x-form-field'> </td></tr></table></form><div>" +
       "&nbsp;&nbsp;<input type='checkbox' id='notImRepeat' value='ON' checked disabled>&nbsp;光盘卷标和文件名重复记录时,不导入<br><div id='divfileinfo'>　　　<div>",
        buttons: [{
            text     : '导入',
            id:'btntd',
            handler  : function(){
            	var total=240;
            	var cur=0;
            	var remoteTotal;
            	me.file = uploadDbForm.filename;
            	if (!me.file.value)
            	  return;
            	me.divfileinfo = divfileinfo;
            	me.notImRepeat = notImRepeat;
				var fpath=me.file.value;
				if(fpath!=""){
					var pos=fpath.lastIndexOf("\\");
					me.fname=fpath.substr(pos+1);
					me.fn=me.fname;
				}
				var f = function(){
		   	 	//var total=f.taskTotal;
		 		var req={"map":{"psMap":{map:{'method':'P','tid':f.taskId},"javaClass":"java.util.HashMap"},"SN":"TaskHandle"},"javaClass":"java.util.HashMap"};
		   	 	jsonrpc.BH.handle(function(data){
		   	 		var cur = parseInt(data[0][0]);
		   	 		var info = data[0][1];
		   	 		//todo
		   	 		var total = parseInt(data[0][2]);
		 			if(cur>=0)
		 			f.taskCur=cur;
			 		var cur=f.taskCur;
			 		//fs.getComponent('pbar2').updateProgress(cur/total,cur+'/'+total+'['+info+']'); 
			 		Ext.MessageBox.updateProgress(cur/total, cur + '/'+total);
			 		Ext.MessageBox.updateText(info);
			 		if(cur<total)
			 		  setTimeout(f, 1000);
			 		else{
			       	  	Ext.MessageBox.hide();
			       	  	delete me.taskTotal;
			       	  	//TODO change value
			       	  	//me.fireEvent("uploaded", me,me.fn );
			       	  	//me.setValue(me.fn);
			       	  	if (info)
			       	  	  me.divfileinfo.innerHTML="　　　"+info;
			 		}
		   	 	 },[req]);  		
		       };

		 		var req={"map":{"psMap":{map:{'method':'N'},"javaClass":"java.util.HashMap"},"SN":"TaskHandle"},"javaClass":"java.util.HashMap"};
		   	 	jsonrpc.BH.handle(function(data){
		   	 		var tid = data[0];
		   	 		f.taskId = tid;
        			me.fn="_["+tid+"]"+me.fname;
        			fm = uploadDbForm;
        			//alert(fm.filename);
    				var oa=fm.action;
    				var username=Bat.gvs.wf_user;
    				fm.action+="?tid="+f.taskId+"&username="+username+"&notImRepeat="+me.notImRepeat.checked;
    				fm.submit();
    				fm.action=oa;					
     		       setTimeout(f, 1000);
		   	 	 },[req]);  		
        		
		        Ext.MessageBox.show({
		           title: '导入',
		           msg: '初始化...',
		           width:total,
		           progress:true,
		           closable:false,
		           animEl: btntd
		       }); 
            }
        }]
    });
	CC.DlgImgImport=dlg;
  }
	dlg.show();
	},
	showCharMapping:function(btn){
	  var ui=btn.ui;
	  var dlg =CC.DlgCharMapping; 
	  if(!dlg){
		var items_tab=[];
		var start =0;
		for(var i=0; i<11; i++){
			var it = {
				autoScroll: false,
				bodyStyle:'padding:0px',
				title:CM_slen4(start),
				start:start,
				listeners: {activate: function(tab){
					renderTabByStart(tab);
				}
			}
			};
		items_tab[items_tab.length]=it;
		start +=100;
		}
  	var cfg ={
        activeTab: 0,
        border:false,
        deferredRender:false,
        enableTabScroll:true,
        defaults:{
    	autoHeight:true, 
    	autoScroll:true,
    	bodyStyle:'padding:10px'}, 
        items:items_tab	
 	};
 	var clipfield;
    dlg = new Ext.Window({
		title		  :'生僻字选择',
        layout      : 'fit',
        width       : 540,
        height      : 420,
        closeAction :'hide',
        plain       : true,
        items       : new Ext.TabPanel(cfg),
        buttons: [
	        clipfield = new Ext.form.TextField( {
			} ),{
            text     : '关闭',
            handler  : function(){
                CC.DlgCharMapping.hide();
            }
        }]
    });
    dlg.clipfield = clipfield;
	CC.DlgCharMapping=dlg;
  }
	dlg.show();
	},
  showPubObj:function(btn){
	var ui=btn.ui;
    var sels=ui.grid.getSelections();
    if(!sels || sels.length==0) return;
   	var robj =sels[0].obj; 
	var cns = ui.req.map.psMap.map.cns;
   	var ko = Bat.gvs.ovs[cns[0]];
   	var kval;
   	var ktitle;
   	var ktitle_uk;
   	if(ko){
   	  var kn = ko.key;
   	  if(cns.length>1)
   	    kn = "A."+kn;
   	  kval = robj.items.map[kn];
   	  var kn_title = ko.title;
   	  if(cns.length>1){
   	  	var kn_title_uk = "B."+kn_title;
   	  	ktitle_uk=robj.items.map[kn_title_uk];
   	  	kn_title = "A."+kn_title;

   	  }
   	  ktitle=robj.items.map[kn_title];
   	}
  if(!CC.pubObjDlg){
  	var func_disinct = function(hql,cb){
    	var req={"map":{"psMap":{map:{'method':'S','hql':hql},"javaClass":"java.util.HashMap"}},"javaClass":"java.util.HashMap"};
		jsonrpc.BH.handle(function(data){
			cb(data);
		},[req]);            	  		
  	}
  	var func_get = function(hql,cns,pss,cb){
    	var req={"map":{"psMap":{map:{'method':'G','hql':hql,"rownum" :1,start:0,'cns':cns,'pss':pss},"javaClass":"java.util.HashMap"}},"javaClass":"java.util.HashMap"};
		jsonrpc.BH.handle(function(data){
			cb(data);
		},[req]);            	  		
  	}

  	var func_put = function(fldmap,cb){
    	func_get("from RpArticle where chanel='"+fldmap['chanel']
    	+"' and template='"	+ fldmap['template']
    	+"' and tablename='" + fldmap['tablename']
    	+"' and idfield='"+fldmap['idfield']+"'",
    	['dao.hb.RpArticle'],[['id','chanel']],
    	function(data){
    		if(data[0].length>1){
    			 cb([[[data[0][1].items.map]]]);
    		}
    		else{
		  		var objs = [{"action":"A","cns":["dao.hb.RpArticle"],"javaClass":"net.bat.prototype.Obj","items":{"javaClass":"java.util.HashMap","map":fldmap}}];
				var req={"map":{"psMap":{"map":{'method':'Q',"objs":objs,"pss":[["id","chanel","template","ord","status","tablename","idfield","lastupdate","title","publishData","descLen"]],"cns":["dao.hb.RpArticle"],"hql":"","start":0},"javaClass":"java.util.HashMap"},"SN":null},"javaClass":"java.util.HashMap"};
			  	jsonrpc.BH.handle(function(data,ex){
			   		if(outputEx(ex,'发布数据异常'))
			   			return;
			   		cb(data);
			  	},[req]);
		    }
    	});
  	}
	var storeTPCN =new Ext.data.SimpleStore({
        fields: ['txt', 'val'],
        data : [] 
    });
    var coboTPCN= new Ext.form.ComboBox({
        fieldLabel: '模板',
        store:storeTPCN ,
        displayField:'txt',
        typeAhead: true,
        mode: 'local',
        triggerAction: 'all',
        emptyText:'...',
        selectOnFocus:true,
        name:'pod_tp_cn'
    });
	var storeCHACN =new Ext.data.SimpleStore({
        fields: ['txt', 'val'],
        data : [] 
    });
    var coboCHACN= new Ext.form.ComboBox({
        fieldLabel: '网站频道',
        store:storeCHACN ,
        displayField:'txt',
        valueField :'val',
        typeAhead: true,
        mode: 'local',
        triggerAction: 'all',
        emptyText:'...',
        selectOnFocus:true,
        name:'pod_cha_cn'
    });
    coboTPCN.on('select',function(cobo,record,index){
    	func_disinct("select distinct A.chanel,B.name from RpArticle A,BaseWebsiteclass B where A.template='"
    	+record.data.val+"' and B.id=A.chanel",function(data){
    		var rl = data[0][0].list;
    		var opts = [];
			for(var i=0;i<rl.length; i++)
				opts[opts.length]=[rl[i][1],rl[i][0]];
			storeCHACN.loadData(opts);    	
			if(opts.length==1){
			  coboCHACN.setValue(opts[0][1]);
			  coboCHACN.fireEvent("select",coboCHACN,storeCHACN.getAt(0),0);
			}
    	});
    });   
    coboCHACN.on('select',function(cobo,record,index){
    	func_get("from RpArticle where chanel='"
    	+record.data.val+"' and template='"
    	+coboTPCN.getValue()+"' and tablename='"
    	+dlg.find('name','pod_cn_cn')[0].getValue()
    	+"' and idfield='"+dlg.find('name','pod_id_cn')[0].getValue()+"'",
    	['dao.hb.RpArticle'],[['id','chanel']],
    	function(data){
    		var btn = CC.pubObjDlg.buttons[2];
    		var btn_pub = CC.pubObjDlg.buttons[0];
    		if(data[0].length>1){
    		  var ro = data[0][1].items.map;
    		  btn.shtml = '/shtml/'+ro['chanel']+'/@/'+ro['id']+'.html'
    		  btn.enable();
    		  btn_pub.disable();
    		}
    		else{
    		  btn.disable();
    		  btn_pub.enable();
    		}
    	});
    });   
	var storeTPUK =new Ext.data.SimpleStore({
        fields: ['txt', 'val'],
        data : [] 
    });
    var coboTPUK= new Ext.form.ComboBox({
        fieldLabel: '模板',
        store:storeTPUK ,
        displayField:'txt',
        typeAhead: true,
        mode: 'local',
        triggerAction: 'all',
        emptyText:'...',
        selectOnFocus:true,
        name:'pod_tp_uk'
    });
	var storeCHAUK =new Ext.data.SimpleStore({
        fields: ['txt', 'val'],
        data : [] 
    });
    var coboCHAUK= new Ext.form.ComboBox({
        fieldLabel: '网站频道',
        store:storeCHAUK ,
        displayField:'txt',
        valueField :'val',
        typeAhead: true,
        mode: 'local',
        triggerAction: 'all',
        emptyText:'...',
        selectOnFocus:true,
        name:'pod_cha_uk'
    });
    coboTPUK.on('select',function(cobo,record,index){
    	func_disinct("select distinct A.chanel,B.name from RpArticle A,BaseWebsiteclass B where A.template='"
    	+record.data.val+"' and B.id=A.chanel",function(data){
    		var rl = data[0][0].list;
    		var opts = [];
			for(var i=0;i<rl.length; i++)
				opts[opts.length]=[rl[i][1],rl[i][0]];
			storeCHAUK.loadData(opts);    	  
			if(opts.length==1)
			  coboCHAUK.setValue(opts[0][1]);
			  coboCHAUK.fireEvent("select",coboCHAUK,storeCHAUK.getAt(0),0);
    	});
    });   
    coboCHAUK.on('select',function(cobo,record,index){
    	func_get("from RpArticle where chanel='"
    	+record.data.val+"' and template='"
    	+coboTPUK.getValue()+"' and tablename='"
    	+dlg.find('name','pod_cn_uk')[0].getValue()+"' and idfield='"+dlg.find('name','pod_id_cn')[0].getValue()+"'",
    	['dao.hb.RpArticle'],[['id','chanel']],
    	function(data){
    		var btn = CC.pubObjDlg.buttons[3];
    		var btn_pub = CC.pubObjDlg.buttons[1];
    		if(data[0].length>1){
    		  var ro = data[0][1].items.map;
    		  btn.shtml = '/shtml/'+ro['chanel']+'/@/'+ro['id']+'.html'
    		  btn.enable();    	
    		  btn_pub.disable();
    		}
    		else{
    		  btn.disable();
    		  btn_pub.enable();
    		}
    	});
    });   

    var fs = new Ext.FormPanel({
    	bodyStyle:'padding:5px 5px 0',
        frame: true,
        width: 450,
        height:200,
        
     items: [{ xtype:'fieldset',
        		collapsible: true,
        		autoHeight:true,
                title: '中文',
                defaults: {width: 250},
                defaultType: 'textfield',
        items: [{
	            fieldLabel: '编号',
	            name: 'pod_id_cn',
	            readOnly:true
	        },{
	            fieldLabel: '题名',
	            name: 'pod_title_cn',
	            readOnly:true
	        },{
	            fieldLabel: '类型',
	            name: 'pod_cn_cn',
	            width:250,
	            readOnly:true
	        },coboTPCN,coboCHACN]
         },{ xtype:'fieldset',
        		collapsible: true,
                title: '英文',
                autoHeight: true,
                defaults: {width: 250},
                defaultType: 'textfield',
        items: [{
	            fieldLabel: '题名',
	            name: 'pod_title_uk',
	            readOnly:true
	        },{
	            fieldLabel: '类型',
	            name: 'pod_cn_uk',
	            readOnly:true
	        },coboTPUK,coboCHAUK]
         }]
    });
 
    dlg  = new Ext.Window({
    	//bodyStyle:'padding:5px;',
    		closeAction:'hide',
            title: '对象发布',
            layout:'fit',
            width:500,
            height:420,
            plain: true,
            items:fs,
            buttons: [{
                text:'发布中文',
                handler: function(btn){
                	func_put({"tablename":dlg.find('name','pod_cn_cn')[0].getValue(),
                	"idfield":dlg.find('name','pod_id_cn')[0].getValue(),
                	"chanel":coboCHACN.getValue(),
                		"template":coboTPCN.getValue(),
                		"title":dlg.find('name','pod_title_cn')[0].getValue(),
                		"status":"2","id":null},
                		function(data){
                		 var ro = data[0][0][0];
			    		var btn = CC.pubObjDlg.buttons[2];
			    		var btn_pub = CC.pubObjDlg.buttons[0];
			    		  btn.shtml = '/shtml/'+ro['chanel']+'/@/'+ro['id']+'.html'
			    		  btn.enable();    	
			    		  btn_pub.disable();               		 
                	});
                }
            },{
                text:'发布英文',
                handler: function(){
                	func_put({"tablename":dlg.find('name','pod_cn_uk')[0].getValue(),
                	"idfield":dlg.find('name','pod_id_cn')[0].getValue(),
                	"chanel":coboCHAUK.getValue(),
                		"template":coboTPUK.getValue(),
                		"title":dlg.find('name','pod_title_uk')[0].getValue(),
                		"status":"2","id":null},
                		function(data){
                		 var ro = data[0][0][0];
			    		var btn = CC.pubObjDlg.buttons[3];
			    		var btn_pub = CC.pubObjDlg.buttons[1];
			    		  btn.shtml = '/shtml/'+ro['chanel']+'/@/'+ro['id']+'.html'
			    		  btn.enable();    	
			    		  btn_pub.disable();               		 
                	});
                }
            },{
                text: '预览中文',
                handler: function(btn){
			 		preview_html(btn.shtml,'_blank');
                    
                }
            },{
            	name: 'btn_preview_uk',
                text: '预览英文',
                handler: function(btn){
                    preview_html(btn.shtml,'_blank');
                }
            }]
     });
     dlg.func=func_disinct;
     dlg.storeTPCN=storeTPCN;
     dlg.storeTPUK=storeTPUK;
     dlg.storeCHACN=storeCHACN;
     dlg.storeCHAUK=storeCHAUK;
     CC.pubObjDlg=dlg ;
    }
    var dlg = CC.pubObjDlg;
    dlg.show();	
    for(var i=0; i<4; i++)
      dlg.buttons[i].disable();
    dlg.func("select distinct template from RpArticle where tablename='"
    	+cns[0]+"' and template not like '%/jsp/web/subject/%' and template not like '%/jsp/web_uk/subject/%'",function(data){
    	var rl = data[0][0].list;
		var opts = [];
		for(var i=0;i<rl.length; i++)
			opts[opts.length]=[rl[i],rl[i]];
		dlg.storeTPCN.loadData(opts);    		
    });
    dlg.find('name','pod_id_cn')[0].setValue(kval);
    dlg.find('name','pod_title_cn')[0].setValue(ktitle);
    dlg.find('name','pod_cn_cn')[0].setValue(cns[0]);
    dlg.find('name','pod_tp_cn')[0].setValue("");
    dlg.find('name','pod_tp_uk')[0].setValue("");
    dlg.find('name','pod_cha_cn')[0].setValue("");
    dlg.find('name','pod_cha_uk')[0].setValue("");
    dlg.find('name','pod_title_uk')[0].setValue("");
    dlg.storeCHACN.loadData([]);
	 dlg.storeCHAUK.loadData([]);
    if(cns.length>1){
        dlg.find('name','pod_cn_uk')[0].setValue(cns[1]);
        dlg.find('name','pod_title_uk')[0].setValue(ktitle_uk);
	    dlg.func("select distinct template from RpArticle where tablename='"
	    	+cns[1]+"' and template not like '%/jsp/web/subject/%' and template not like '%/jsp/web_uk/subject/%'",function(data){
	    	var rl = data[0][0].list;
			var opts = [];
			for(var i=0;i<rl.length; i++)
				opts[opts.length]=[rl[i],rl[i]];
			dlg.storeTPUK.loadData(opts);    		
	    });
    }else {
    	dlg.find('name','pod_cn_uk')[0].setValue("");
    	dlg.find('name','pod_tp_uk')[0].setValue("");
    	dlg.storeTPUK.loadData([]); 
    }
	},
		
	showImport:function(em){
      if(!CC.importDlg){ // lazy initialize the dialog and only create it once
		var f = function(){
		//alert('f');
   	 	var total=f.taskTotal;
 		var req={"map":{"psMap":{map:{'method':'P','tid':f.taskId},"javaClass":"java.util.HashMap"},"SN":"TaskHandle"},"javaClass":"java.util.HashMap"};
   	 	jsonrpc_task.BH.handle(function(data){
   	 		//alert(data);
   	 		var cur = parseInt(data[0][0]);
   	 		var info = data[0][1];
 			if(cur>=0)
 			f.taskCur=cur;
	 		var cur=f.taskCur;
	 		fs.getComponent('pbar2').updateProgress(cur/total,cur+'/'+total+'['+info+']'); 
	 		if(cur<total)
	 		  setTimeout(f, 1000);
	 		else{
	    		dlg.buttons[0].setDisabled(false);
	    		dlg.buttons[1].setDisabled(false);
	 		}
   	 	 },[req]);  		
       };
       var onbtn = function(bTest){
    	 var fv = fs.getForm().getValues();
		fv.status = fs.getForm().findField('status').getValue();
		fv.Entity = fs.getForm().findField('Entity').getValue();
		fv.chanel = fs.getForm().findField('chanel').getValue();
		if(bTest)
			fv.bTest=bTest;
    	var req={"map":{"psMap":{map:{'method':'P','fv':{map:fv,"javaClass":"java.util.HashMap"}},"javaClass":"java.util.HashMap"},"SN":"RPHandle"},"javaClass":"java.util.HashMap"};
    	dlg.buttons[0].setDisabled(true);
    	dlg.buttons[1].setDisabled(true);
    	jsonrpc.BH.handle(function(rd,ex){
    		if(outputEx(ex,'页面发布异常')){
	    		dlg.buttons[0].setDisabled(false);
	    		dlg.buttons[1].setDisabled(false);
    			return;
    		}
	       f.taskId=rd[0][0];
	       f.taskTotal=parseInt(rd[0][1]);
	       req.map.psMap.map.tid=f.taskId;
	       req.map.psMap.map.method='I';
	    	jsonrpc.BH.handle(function(rd){
	    		//alert('2222:'+rd[0]);
	    	},[req]);
		   	setTimeout(f, 1000);       
	   	},[req]);       
       }; 
       var ens=Bat.gvs.cen;
		var storeEntity =new Ext.data.SimpleStore({
	        fields: ['txt', 'val'],
	        data : ens 
        });
		var storeField =new Ext.data.SimpleStore({
	        fields: ['txt', 'val'],
	        data : [] 
        });
        
       	var coboEntity=new Ext.form.ComboBox({
            fieldLabel: '对象',
            store:storeEntity ,
            displayField:'txt',
            valueField:'val',
            typeAhead: true,
            mode: 'local',
            triggerAction: 'all',
            emptyText:'...',
            selectOnFocus:true,
            name:'Entity'
	        });
	    coboEntity.on('select',function(cobo,record,index){
	    	var req={"map":{"psMap":{map:{'method':'L','cn':record.data.val},"javaClass":"java.util.HashMap"},"SN":"RPHandle"},"javaClass":"java.util.HashMap"};
	    	jsonrpc.BH.handle(function(data){
				var opts = [];
				for(var i=0;i<data[0].length; i++)
					opts[opts.length]=[data[0][i],data[0][i]];
				storeField.loadData(opts);
		   	},[req]);       
	    });   
        
        var coboField= new Ext.form.ComboBox({
	            fieldLabel: '标题字段',
	            store:storeField ,
	            displayField:'txt',
	            typeAhead: true,
	            mode: 'local',
	            triggerAction: 'all',
	            emptyText:'...',
	            selectOnFocus:true,
	            width:50,
	            name:'titlefld'
	        });
      
    var fs = new Ext.FormPanel({
    	bodyStyle:'padding:5px 5px 0',
        frame: true,
        labelAlign: 'top',
        labelWidth: 120,
        width: 450,
        height:300,
        
     items: [{
        layout:'column',
		xtype: 'panel',
		items:[{
        columnWidth:.5,
        //layout: 'form',
        items: new Ext.form.FieldSet({
                title: '来源',
                autoHeight: true,
                defaults: {width: 200},
                defaultType: 'textfield',
        items: [
        	coboEntity,
        	coboField,
	        new Ext.form.TextField({
	            fieldLabel: 'Filter',
	            name: 'filter',
	            width:150
	        })	        
            ]
         })},
         
		{
        columnWidth:.5,
        //layout: 'form',
        items: new Ext.form.FieldSet({
                title: '目标',
                autoHeight: true,
                defaults: {width: 200},
                defaultType: 'textfield',
        items: [        	
	        createComponentByVW('dao.hb.RpArticle','template'),
	        createComponentByVW('dao.hb.RpArticle','chanel'),
	        createComponentByVW('dao.hb.RpArticle','status'),
	        new Ext.form.TextField({
	            fieldLabel: '备注',
	            name: 'remark',
	            width:150,
	            value: "["+Bat.gvs.wf_user+"]"+new Date().toLocaleDateString()
	        })	        
        
            ]
         })}
         ]},
        new Ext.ProgressBar({
         text:'Ready',
         id:'pbar2',
         cls:'left-align'       		
         })]
    });
 
    dlg  = new Ext.Window({
    	bodyStyle:'padding:5px;',
    		closeAction:'hide',
            title: INFO('批发[批量发布]'),
            layout:'fit',
            width:500,
            height:380,
            plain: true,
            items:fs,
            buttons: [{
            	//disable 避免与kx重复发布
            	disabled:true,
                text:'Test',
                handler: function(){
                	onbtn(true);
                }
            },{
            	//disable 避免与kx重复发布
            	disabled:true,
                text: '发布',
                handler: function(){
                    onbtn(false);
                }
            }]
     });
     CC.importDlg=dlg ;
    }
    CC.importDlg.show();		
	},

	////////////// by gaofei 2009.11.4
	showStaDlg:function(btn){
		var ui=btn.ui;
	    var sels=ui.grid.getSelections();
	    if(!sels || sels.length==0) return;
	   	var robj =sels[0].obj; 
	   	var chanelId =  robj.items.map['A.id'];	   
		if(!win){
			
			 var querySta = function(bTest){
					var st = Ext.getDom("startTime").value;
					var et =  Ext.getDom("endTime").value;
					
					if(st==null||et==null)
						return false;
					var mins =compareDate(st,et)/(24*60*60*1000);	//日期	
					
					/*var hql="";
					var stArr = st.split("-");
					var month_s = stArr[1];
					if(parseInt(month_s)<10)
						st = stArr[0]+"-0"+stArr[1]+"-"+stArr[2];
					var etArr = et.split("-");
					var month_e = etArr[1];
					if(parseInt(month_e)<10)
						et = etArr[0]+"-0"+etArr[1]+"-"+etArr[2];*/
					
					var hql_ = "select sum(selfIpAmount),sum(selfPageAmount),sum(selfFileAmount),sum(totalIpAmount),sum(totalPageAmount),sum(totalFileAmount) from  dao.hb.StaWeblog   where logDate>=to_date('"+st.replace(/\-/g,"")+"','yyyymmdd')"+
					" and channelId='"+Ext.getDom("chanelID").value+"' and logDate<=to_date('"+et.replace(/\-/g,"")+"','yyyymmdd')";					
					var st_text= new Ext.form.ComboBox({
					        fieldLabel: '起始时间',					        
					        displayField:'txt',
					        valueField :'val',
					        typeAhead: true,
					        mode: 'local',
					        triggerAction: 'all',
					        emptyText:'...',
					        selectOnFocus:true,
					        name:'pod_cha_uk'
					    });
			   		var req={"map":{"psMap":{map:{'method':'S',
						"hql" : hql_
						},"javaClass":"java.util.HashMap"},"SN":"DpmHandle"},"javaClass":"java.util.HashMap"};
			   		
					jsonrpc.BH.handle(function(data){
			   	 	var cur = data[0];
			   	 	
			   	 	 Ext.getDom("selfipCount").value = data[0][0];
			   	 	 Ext.getDom("selfpageCount").value = data[0][1];
			   	 	 Ext.getDom("selffileCount").value = data[0][2];
			   	 	 Ext.getDom("totalipCount").value = data[0][3];
			   	 	 Ext.getDom("totalpageCount").value = data[0][4];
			   	 	 Ext.getDom("totalfileCount").value = data[0][5];
			   	 	//ext-comp-1099
			   	 	 
			   	 	 },[req]);      					
					 
			 };
			 
			 
			 
		 win = new Ext.Window({
			 title:'日志统计',
             applyTo:'hello-win',
             //layout:'fit',
             //frame:true, 
             width:600,
             height:420,
             closeAction:'hide',
             plain: true,  
             labelStyle:"width:250px;",
	       
	        items: [
					{ xtype:'fieldset',
						collapsible: true,
						autoHeight:true,
					    title: '请选择时间',					   
					items: [{
						xtype: 'datefield',
					    fieldLabel: '起始日期',
					    labelStyle:"width:150px;",
					    name: 'pod_id_cn',
					    id:'startTime',
					    format:'Y-m-d',
					    width:250,
					    readOnly:true
					},{
						xtype: 'datefield',
					    fieldLabel: '终止日期',
					    labelStyle:"width:150px;",
					    name: 'pod_cn_cn',
					    id:'endTime',
					    format:'Y-m-d',
					    width:250,
					    readOnly:true
					},
						
					   // createComponentByVW('dao.hb.RpArticle','chanel'),
					{
						xtype:'textfield',
						id:'chanelID',
						fieldLabel:'网站频道',
						labelStyle:"width:150px;",
						readOnly:true,
						//style:'border:none;background:none;',
						width:250
						
						
						
						
						
					},
					   
					{ 
		               	 xtype:'button', 
		               	 text: '查询',  
			                 layout:'fit',  
			                handler:function(){
			            	querySta("true");
		                    }
		                   
		                } ]
					},
					{
						xtype:'fieldset',
						collapsible: true,
						autoHeight:true,
						title: '查询结果',
						id:'result_table',
						
						items:[
								{
									xtype: 'label'	,
									id:'selfipCount',
									fieldLabel:'本频道ip访问数',
									labelStyle:"width:150px;",
									//style:'border:none;background:none;',
									readOnly:true,
									width:250
								   
								},{
									xtype: 'textfield'	,
									id:'selfpageCount',
									fieldLabel:'本频道页面访问数',
									labelStyle:"width:150px;",
									//style:'border:none;background:none;',
									readOnly:true,
									width:250
								  
								},{
									xtype: 'textfield'	,
									id:'selffileCount',
									fieldLabel:'本频道文件访问数',
									labelStyle:"width:150px;",
									//style:'border:none;background:none;',
									readOnly:true,
									width:250
								  
								},{
									xtype: 'textfield'	,
									id:'totalipCount',
									fieldLabel:'包含子频道ip访问数',
									labelStyle:"width:150px;",
									//style:'border:none;background:none;',
									readOnly:true,
									width:250
								  
								},{
									xtype: 'textfield'	,
									id:'totalpageCount',
									fieldLabel:'包含子频道页面访问数',
									labelStyle:"width:150px;",
									//style:'border:none;background:none;',
									readOnly:true,
									width:250
								  
								},{
									xtype: 'textfield'	,
									id:'totalfileCount',
									fieldLabel:'包含子频道文件访问数',
									labelStyle:"width:150px;",
									//style:'border:none;background:none;',
									readOnly:true,
									
									width:250
								  
								}
						]
					}
	        ]
	       
	    });
	   
		 
		}
		Ext.getDom("chanelID").value =chanelId ;
		 Ext.getDom("selfipCount").value = "";
   	 	 Ext.getDom("selfpageCount").value = "";
   	 	 Ext.getDom("selffileCount").value = "";
   	 	 Ext.getDom("totalipCount").value = "";
   	 	 Ext.getDom("totalpageCount").value = "";
   	 	 Ext.getDom("totalfileCount").value = "";
		win.show(this);
	},

	
	//////////////
	//条件更新
	showPublish:function(btn,bhql){
	  var ui=btn.ui;
	  ui.grid.getreq();
	  var hql = ui.req.map.psMap.map.hql;
      var total=240;
        Ext.MessageBox.show({
           title: '请稍等...',
           msg: '正在处理请求...',
           width:total,
           progress:true,
           closable:false,
           animEl: btn.el.dom
       });            	
		//TODO 12.5
		var f = function(){
	   	 	var total=f.taskTotal;
    		var req={"map":{"psMap":{map:{'method':'P','tid':f.taskId},"javaClass":"java.util.HashMap"},"SN":"TaskHandle"},"javaClass":"java.util.HashMap"};
	   	 	jsonrpc_task.BH.handle(function(data){
	   	 		var cur = parseInt(data[0][0]);
	   	 		var info = data[0][1];
	 			if(cur>=0)
	 			f.taskCur=cur;
		 		var cur=f.taskCur;
		        Ext.MessageBox.updateProgress(cur/total, cur + '/'+total);
		        Ext.MessageBox.updateText(info);
		       	if(cur>=total){
		       		Ext.MessageBox.hide();
		       	  	delete f.taskTotal;
		       	}
		       	else{
		            setTimeout(f, 1000);
		       	}	   	 		
	   	 	 },[req]); 
       };
        var pm=bhql?{'method':'T','hql':hql}:{'method':'T'};
    	var req={"map":{"psMap":{map:pm,"javaClass":"java.util.HashMap"},"SN":"RPHandle"},"javaClass":"java.util.HashMap"};
    	jsonrpc.BH.handle(function(rd){
	       f.taskId=rd[0][0];
	       f.taskTotal=parseInt(rd[0][1]);
	       req.map.psMap.map.tid=f.taskId;
	       req.map.psMap.map.method='H';
	    	jsonrpc.BH.handle(function(rd){
	    		//alert('2222:'+rd[0]);
	    	},[req]);
		   setTimeout(f, 1000);       
	   	},[req]);       
	},
    //////////////
	//影像提交到正式表  type cur filter
	ImportImageToObj:function(btn,imtype){
	  var ui=btn.ui;
	  ui.grid.getreq();
	  var hql = ui.req.map.psMap.map.hql;
          	
      var t=btn.ui;
	  var sels=t.grid.getSelections();	  	
	  var selid=0;
	  if(imtype=='cur'){
	    if(!sels || sels.length==0) return;
	  	selid = sels[0].obj.items.map['imageId'];
	  }
	  t.grid.getSelectionModel().clearSelections(); 
	  //if (!selid)
	    //selid="6";	  
      var pm={'method':'I','hql':hql,'selid':selid,'imtype':imtype};
      var req={"map":{"psMap":{map:pm,"javaClass":"java.util.HashMap"},"SN":"DpmHandle"},"javaClass":"java.util.HashMap"};
    	jsonrpc.BH.handle(function(rd){
	       //var aa =rd;
	       //f.taskTotal=parseInt(rd[0][1]);
	       //req.map.psMap.map.tid=f.taskId;
	       //req.map.psMap.map.method='H';
	    	//jsonrpc.BH.handle(function(rd){
	    	//},[req]);  
    		alert("提交完成   "+rd);
			ui.load();
	   	},[req]);       
	},	
	showMarking:function(btn){  //wjh 重新打标
	  var ui=btn.ui;
	  ui.grid.getreq();
	  var hql = ui.req.map.psMap.map.hql;
      var total=240;
        Ext.MessageBox.show({
           title: '请稍等...',
           msg: '正在处理请求...',
           width:total,
           progress:true,
           closable:false,
           animEl: btn.el.dom
       });            	
		//TODO 12.5
		var f = function(){
	   	 	var total=f.taskTotal;
    		var req={"map":{"psMap":{map:{'method':'P','tid':f.taskId},"javaClass":"java.util.HashMap"},"SN":"TaskHandle"},"javaClass":"java.util.HashMap"};
	   	 //alert("f");
    		jsonrpc_task.BH.handle(function(data){
	   	 		//alert("getcur "+data);
	   	 		var cur = parseInt(data[0][0]);
	   	 		var info = data[0][1];
	 			if(cur>=0)
	 			f.taskCur=cur;
		 		var cur=f.taskCur;
		        Ext.MessageBox.updateProgress(cur/total, cur + '/'+total);
		        Ext.MessageBox.updateText(info);
		       	if(cur>=total){
		       		ui.grid.stopEditing();
		            ui.grid.getSelectionModel().clearSelections();            
		            ui.req.map.psMap.map.start=0;
		            ui.grid.getreq();
		            ui.load();
		       		Ext.MessageBox.hide();
		       	  	delete f.taskTotal;
		       	}
		       	else{
		            setTimeout(f, 1000);
		       	}	   	 		
	   	 	 },[req]); 
       };
    	var req={"map":{"psMap":{map:{'method':'M','hql':hql,'robjcns':ui.robj.cns[0],'username':Bat.gvs.wf_un,'count':'1'},"javaClass":"java.util.HashMap"},"SN":"RPHandle"},"javaClass":"java.util.HashMap"};
    	//req.robjcns = ui.robj.cns[0];
    	jsonrpc.BH.handle(function(rd){
	       f.taskId=rd[0][0];
	       f.taskTotal=parseInt(rd[0][1]);
	       req.map.psMap.map.tid=f.taskId;
	       req.map.psMap.map.method='N';
	       req.robjcns = ui.robj.cns[0];
	       //alert(req.robjcns);
	    	jsonrpc.BH.handle(function(rd){
	    	},[req]);
	    	//alert("settimeout");
		   setTimeout(f, 1000);       
	   	},[req]);       
	},	
	
    //打开打标操作窗体,进行打标	
	showMarkingDlg:function(em){
      if(!CC.MarkingDlg){ // lazy initialize the dialog and only create it once
		var f = function(){
		//alert('f');
   	 	var total=f.taskTotal;
 		var req={"map":{"psMap":{map:{'method':'P','tid':f.taskId},"javaClass":"java.util.HashMap"},"SN":"TaskHandle"},"javaClass":"java.util.HashMap"};
   	 	jsonrpc_task.BH.handle(function(data){
   	 		//alert(data);
   	 		var cur = parseInt(data[0][0]);
   	 		var info = data[0][1];
 			if(cur>=0)
 			f.taskCur=cur;
	 		var cur=f.taskCur;
	 		fs.getComponent('pbar_marking').updateProgress(cur/total,cur+'/'+total+'['+info+']'); 
	 		if(cur<total)
	 		  setTimeout(f, 1000);
	 		else{
	 		  //alert('ok=====');
	 		}
	 		
   	 	 },[req]);  		
       };
       
       var onbtn = function(bTest){
		var fv = fs.getForm().getValues();
		fv.status = fs.getForm().findField('status').getValue();
		fv.Entity = fs.getForm().findField('Entity').getValue();
		//fv.chanel = fs.getForm().findField('chanel').getValue();
		if(bTest)
			fv.bTest=bTest;
    	var req={"map":{"psMap":{map:{'method':'M','fv':{map:fv,"javaClass":"java.util.HashMap"},'username':Bat.gvs.wf_un,type:'table'},"javaClass":"java.util.HashMap"},"SN":"RPHandle"},"javaClass":"java.util.HashMap"};
    	fs.getComponent('pbar_marking').updateProgress(0,'请稍候...'); 
    	jsonrpc.BH.handle(function(rd){
	       f.taskId=rd[0][0];
	       f.taskTotal=parseInt(rd[0][1]);
	       req.map.psMap.map.tid=f.taskId;
	       req.map.psMap.map.method='N';            //N:开始任务 , M:建立任务
	       req.map.psMap.map.type='table'; //wjh
	       req.map.psMap.map.username=Bat.gvs.wf_un; 
	    	jsonrpc.BH.handle(function(rd){
	    		//alert('2222:'+rd[0]);	    		
	    	},[req]);
		   	setTimeout(f, 1000);       
	   	},[req]);       
       }; 
      
       
       var ens=Bat.gvs.ens;
		var storeEntity =new Ext.data.SimpleStore({
	        fields: ['txt', 'val'],
	        data : ens 
        });
		var storeField =new Ext.data.SimpleStore({
	        fields: ['txt', 'val'],
	        data : [] 
        });
        
       	var coboEntity=new Ext.form.ComboBox({
            fieldLabel: '对象',
            store:storeEntity ,
            displayField:'txt',
            valueField:'val',
            typeAhead: true,
            mode: 'local',
            triggerAction: 'all',
            emptyText:'...',
            selectOnFocus:true,
            name:'Entity'
	        });
	    coboEntity.on('select',function(cobo,record,index){
	    	var req={"map":{"psMap":{map:{'method':'L','cn':record.data.val},"javaClass":"java.util.HashMap"},"SN":"RPHandle"},"javaClass":"java.util.HashMap"};
	    	jsonrpc.BH.handle(function(data){
				var opts = [];
				for(var i=0;i<data[0].length; i++)
					opts[opts.length]=[data[0][i],data[0][i]];
				storeField.loadData(opts);
		   	},[req]);       
	    });   
        
        var coboField= new Ext.form.ComboBox({
	            fieldLabel: '描述字段',
	            store:storeField ,
	            displayField:'txt',
	            typeAhead: true,
	            mode: 'local',
	            triggerAction: 'all',
	            emptyText:'...',
	            selectOnFocus:true,
	            width:50,
	            name:'titlefld'
	        });
      
    var fs = new Ext.FormPanel({
    	bodyStyle:'padding:5px 5px 0',
        frame: true,
        labelAlign: 'top',
        labelWidth: 120,
        width: 450,
        height:300,
        
     items: [{
        layout:'column',
		xtype: 'panel',
		items:[{
        columnWidth:.5,
        //layout: 'form',
        items: new Ext.form.FieldSet({
                title: '',//来源
                autoHeight: true,
                defaults: {width: 200},
                defaultType: 'textfield',
        items: [
        	coboEntity, //对象
        	coboField,  //描述字段
	        new Ext.form.TextField({
	            fieldLabel: 'Filter',
	            name: 'filter',//where objId=404
	            width:150
	        })//Filter	        
            ]
         })},
         
		{
        columnWidth:.5,
        //layout: 'form',
        items: new Ext.form.FieldSet({
                title: '',//目标
                autoHeight: true,
                defaults: {width: 200},
                defaultType: 'textfield',
        items: [        	
	        //createComponentByVW('dao.hb.RpArticle','template'),
	        //createComponentByVW('dao.hb.RpArticle','chanel'),
	        createComponentByVW('dao.hb.RpArticle','status')  //状态      
            ]
         })}
         ]},
        new Ext.ProgressBar({
         text:'Ready',
         id:'pbar_marking',
         cls:'left-align'       		
         })]
    });
 
    dlg  = new Ext.Window({
    	bodyStyle:'padding:5px;',
    		closeAction:'hide',
            title: INFO('打标'),
            layout:'fit',
            width:500,
            height:330,
            plain: true,
            items:fs,
            buttons: [{
                text:'Test',
                handler: function(){
                	onbtn("true");
                }
            },{
                text: '打标',
                handler: function(){
                    onbtn("false");
                }
            }]
     });
     CC.MarkingDlg=dlg ;
    }
    CC.MarkingDlg.show();		
	},	

	tbar:null,
	login:function(succfunc,login_f,bUM){
		var hql = "select username,name from dao.hb.AvensResource where userdn like '%zhanshineirongcaibianke%' or userdn like '%zhanshijishuke%' or username like 'avens_%'";
		if(bUM && bUM.indexOf('?iam')==0){
			var un=bUM.substring(5);
			hql = "select username,name from dao.hb.AvensResource where name ='"+un+"'";
		}
	    var loginfm = new Ext.form.FormPanel({
        baseCls: 'x-plain',
        labelWidth: 55,
        url:'save-form.php',
        defaultType: 'textfield',
		//defaults: {width: 210},
        items: [{
            xtype:'fieldset',
            autoHeight:true,
            title: '登录信息',
             defaultType: 'textfield',
            items:[{
            	fieldLabel:'尊姓大名',
            	mode:'local',
            	name:'user',
            	xtype:'combo',
            	lazyInit:false,
            	emptyText :'请选择',
            	displayField:'name',
            	valueField :'id',
            	triggerAction:'all',
            	typeAhead :true,
             	store:new Ext.data.Store({
            		baseParams:{hql:hql},
	            	autoLoad:true,
	            	proxy:new Ext.data.HttpProxy({
	            	 method:'post',
	            	 url:'/cc/servlet/JSonBaseServlet?'}),
	            	 reader:new Ext.data.ArrayReader(
	            		{id:0,root:'result'},
	            		Ext.data.Record.create([
	            		 {name: 'id'},{name:'name'}
	            		])),
            		 remoteSort:true})
            	},{
            fieldLabel: '密码',
            name: 'pwd',
           // value: '111111',
            inputType: 'password'
        }]}, {
            xtype:'fieldset',
            checkboxName:'changepwd',
            checkboxToggle:true,
            title: '修改密码',
            //collapsible: true,
            collapsed: true,
            autoHeight:true,
            defaultType: 'textfield',
            //defaults: {width: 210},
            items :[{
                    fieldLabel: '新密码',
                    name: 'pwd1',
                    inputType: 'password',
                    value: ''
                },{
                    fieldLabel: '确认密码',
                    inputType: 'password',
                    name: 'pwd2',
                   	validator:function(val){
                   	  	if(val==loginfm.getForm().findField('pwd1').getValue())
		            	  return true;
		            	else  return '密码输入不一致';  
		            }	                                
                }
             ]
        }]        
    });
    //form.render(document.body);
	//return;
    var loginwin = new Ext.Window({
    	shadow: false,
        title: '用户登录',
        width: 400,
        //height:300,
        autoHeight:true,
        layout: 'form',
        plain:true,
        bodyStyle:'padding:5px;',
        buttonAlign:'center',
        items: loginfm,
		defaultButton:'id_ok',
        buttons: [{
        	id:'id_ok',
            text: '确定',
            handler: function(){
            	var ps = loginfm.getForm().getValues();
            	if(ps.changepwd){ 
            		if(ps.pwd1!= ps.pwd2)
            	 		return false;
            	}else{
            		delete ps.pwd1;
            		delete ps.pwd2;
            	}
            	Bat.gvs.wf_userName=ps.user;
            	ps.user =  loginfm.getForm().findField('user').getValue();
            	ps.method = "L";
            	login_f(ps,function(){
            		loginwin.hide();            	
        			succfunc();            		
            	});
            }            
        },{
            text: '取消',
            handler: function(){
            	loginwin.hide();
            }
        }]
    });

    loginwin.show();
		
	},
	about:{
		name:'Content Editor',
		version:'rc1',
		auhtor:'hhdd',
		date:'2009-12'
	},
  UI:{},
initToolbar:function(){
    var store = new Ext.data.SimpleStore({
        fields: ['abbr', 'state'],
        data : [["default","default"],["aero","aero"],["gray","gray"],["vista","vista"]] // from states.js
    });
   var ths=[['default','default'],['slickness','slickness'],['slate','slate'],['purple','purple'],['pink','pink']
    ,['olive','olive'],['midnight','midnight'],['indigo','indigo'],['green','green'],['gray','gray'],['darkgray','darkgray']
    ,['calista','calista'],['black','black'],['galdaka','galdaka'],['orange','orange'],['red5','red5'],['silverCherry','silverCherry'],['slate','slate'],['slickness','slickness']];
  	var themeItems=[];
    for(var i=0,len=ths.length; i<len; i++){
    	themeItems[themeItems.length]=new Ext.menu.CheckItem({
            text: ths[i][0],
			value: ths[i][1],
            group: 'theme',
            checkHandler: onItemCheck
        });
    }
	for(var i=0,len=themeItems.length; i<len; i++){
		if(themeItems[i].value==cookie_theme){
			themeItems[i].setChecked(true,true);
			break;
		}
	}
	 return {
	 	region:'north',
	 	items:[{
		    text:INFO('Options'),
         	cls: 'x-btn-text-icon',
         	icon: '../img/star.gif',
            menu: {
			items: [{
			 text:'生僻字',
				handler:function(btn){
				  CC.showCharMapping(btn);
			  }
			},{
			 text:'用户手册',
				handler:function(btn){
					window.open("../../hlp/book.htm",'_blank');
			  }
			},{
			 text:'封面手册',
				handler:function(btn){
					window.open("../../hlp/cover.xls",'_blank');
			  }
			},{
			 text:'工具软件',
				handler:function(btn){
				  var tabPanel = viewport.getComponent('center');
				  tabPanel.add({
					bodyStyle:'padding:10px;font-size:12px;',
		            title: '工具软件说明',
		            iconCls: 'tabs',
		            contentEl: 'tabs_tools',
		            closable:true
		        }).show();
			  }
			},			
			//{text: INFO('Theme'),menu: { items:themeItems}},
			{text:INFO('About'),
				handler:function(){Ext.MessageBox.show({title:'关于', 
				msg:'<p align=\'center\'>'+CC.about.name+ ' '+CC.about.version+' <br><font color="#FF0000">'+CC.about.date+'</font></p>',
				buttons: Ext.MessageBox.OK,
				width:220
			});}}]
		 }},{
		 id:'mi_save',
         cls: 'x-btn-text-icon',
         icon: '../img/save2.gif',
		 text:'保存',
		 disabled:true,
		 handler:function(){
			var tabPanel = viewport.getComponent('center');
			var ap = tabPanel.getActiveTab()||{};
			var t = ap.ui;
			if(!t || t.renderMode!=Bat.UI.RENDER.EDIT) 
				return;
			//t.req.map.SN = 'AvensHandle';
			t.save(function(t){
		  		tabPanel.setActiveTab(ap.pPanel);
		  		ap.pPanel.ui.load();
		  		tabPanel.hideTabStripItem(ap);
		  		ap.hide();
			});
		}
		},{
		id:'mi_submit',
         cls: 'x-btn-text-icon',
         icon: '../img/nav.gif',
		text:'提交',
		disabled:true,
		handler:function(){
			var tabPanel = viewport.getComponent('center');
			var ap = tabPanel.getActiveTab()||{};
			var t = ap.ui;
			if(!t || t.renderMode!=Bat.UI.RENDER.EDIT) 
				return;
			Ext.MessageBox.wait('正在提交，请稍候...'); 
			var rm = t.req.map.psMap.map;
			if(rm.cns[0]=='avens.formsado.dpm_ce.dpm_ce_ado'){			
				rm.method='S';
			}
			else{
				rm.packageId='dpm_ce';
				rm.processDefinitionId='dpm_ce';
				rm.method='N';
			}
		  	rm.objs=t.objs;
			t.req.map.SN = 'AvensHandle';
			var reqs = [t.req];
			var func_submit = t.func_submit;
			if(func_submit)
				func_submit(reqs);
		  	jsonrpc.BH.handle(function(data,ex){
        		if(outputEx(ex,'提交工作单异常'))
        			return;
		  		delete rm.objs;
		  		t.fireEvent("after_put",t,true);
		  		tabPanel.setActiveTab(ap.pPanel);
		  		ap.pPanel.ui.loadCurpage();
		  		tabPanel.hideTabStripItem(ap);
		  		ap.hide();
		  		Ext.MessageBox.hide();
		  	},reqs);
			
	 	}
		},{
		 id:'mi_exit',
         cls: 'x-btn-text-icon',
         icon: '../img/act_exit.gif',
		 text:'退出',
		 handler:function(){
		 	Ext.MessageBox.confirm('退出', '确认要退出系统吗?', function(e){
		 		if(e=='yes')
		 		  document.location='/cc/servlet/authenticate?cmd=logout';
		 	});
		 }
		},
		'->',CC.welcome_text
		]};
	},

initWfTree:function(id,title,iconCls){
	var root = new Ext.tree.TreeNode({
		text: INFO('Workflow'), 
		allowDrag:false,
		allowDrop:false
	});
	var nn;
	
	nn={
		//"New":{fv:'新建',fn:'vn',ns:Bat.gvs.ovs_fvcn	},
		"Draft":{fv:'草稿',fn:'vn',ns:Bat.gvs.ovs_fvdraft	},
		"待办":'wf_pending',
		"已办":'wf_history'
		//,"全部已办":'wf_history',
		//"上下文":'wf_ctx_cc',
		//'工作单——对象':'rel_avens_cc'
	};
	for(var x in nn){
	  if((typeof nn[x])=='string'){
		  root.appendChild(
			new Ext.tree.TreeNode({text:INFO(x), vn:nn[x],allowDrag:false,allowDrop:false})); 
	  }else{
	  	buildNode(root,nn[x]);
	  }
	}   
   var tree = new Ext.tree.TreePanel( {
		id:id,
		title:title,
		iconCls:iconCls,
		root:root,
		animate:true, 
		enableDD:true,
		containerScroll: true,
		ddGroup: 'wfDD',
		rootVisible:true
	});
	tree.on('click',function(node,e){
		var pn = node.parentNode;
		var fv = pn.fv;
		var t;
		if(fv=='新建')
		  t = renderNodeEdit(node,nn);
		else if(fv=='草稿')
		  t = renderGridByNode(node,nn,function(cv){
	  	  var vmap = cv.req.map.psMap.map;
		  getAdoHQL(vmap);
			var btns_hide = cv.grid.hidebtns_objmode;
			if(btns_hide){
				var btns = cv.grid.btns;
				for(var i=0; i<btns_hide.length; i++){
					btns[btns_hide[i]]=null;
				}
			}
			  var btns = cv.grid.btns;
			  var av = node.fv;
			  if(av=='影像'){
			  btns[btns.length]={
			  		text: '导入',
			   		iconCls: 'import',
					handler : function(btn){
						CC.showImgImport(btn);
					}
				};
				btns[btns.length]={
			  		text: '提交到正式表',
			   		iconCls: 'import',
					menu: {
						items: [{
						  text: '当前选中的记录',
			   		      iconCls: 'import',			   		
					      handler : function(btn){
						    CC.ImportImageToObj(btn,"cur");
					      }
						},
						{
						  text: '按过滤条件提交',
			   		      iconCls: 'import',			   		
					      handler : function(btn){
						    CC.ImportImageToObj(btn,"filter");
					      }
						}
						]
					}
				};
			  }
			  if(av=='文物'){
			  btns[btns.length]={
			  		text: '导入',
			   		iconCls: 'import',
					handler : function(btn){
						var t=btn.ui;
				        Ext.MessageBox.show({
				           title: '导入文物',
				           msg: '请输入文物编号(分号分隔):',
				           width:300,
				           buttons: Ext.MessageBox.OKCANCEL,
				           multiline: true,
				           fn: function(btn,txt){
				           	 if(btn=='cancel') return false;
				           	var rnos = txt.split(";");
				           	var rtxt="";
				           	for(var i=0; i<rnos.length; i++){
				           		if(i==0)
				           		  rtxt = reset_rnum(rnos[i]);
				           		else
				           		  rtxt+=";"+reset_rnum(rnos[i]);
				           	}
				            var req={"map":{"psMap":{map:{method:'R',ros:rtxt},"javaClass":"java.util.HashMap"},"SN":"DpmHandle"},"javaClass":"java.util.HashMap"};
				            jsonrpc.BH.handle(function(data,ex){
				        		if(outputEx(ex,'导入文物异常'))
				        			return;
						  		t.load();
						  		//Ext.MessageBox.hide();
				           	},[req]);            	
				           	//alert('to import!');
				           },
				           animEl:btn
				       });
					}
				};
			  }
			  btns[btns.length]={
			  		text: '提交',
			   		iconCls: 'workflow',
					handler : function(btn){
						var t=btn.ui;
		    	 		var sels=t.grid.getSelections();
			    		if(!sels) return;						
						Ext.MessageBox.wait('正在提交，请稍候...'); 
						var req =Bat.clone( t.req);
						var rm = req.map.psMap.map;
						rm.packageId='dpm_ce';
						rm.processDefinitionId='dpm_ce';
						rm.method='N';
						rm.objs=[sels[0].obj];
						//服务暂时不能处理多个草稿提交
						/*for(var i=0; i<sels.length; i++){
							rm.objs[rm.objs.length]=sels[i].obj;
						}*/
						req.map.SN = 'AvensHandle';
						var reqs = [req];
					  	jsonrpc.BH.handle(function(data,ex){
			        		if(outputEx(ex,'提交工作单异常'))
			        			return;
					  		t.loadCurpage();
					  		Ext.MessageBox.hide();
					  	},reqs);
					}
				};
			  return cv;
		  });
		else{
			if(node.text=='待办')
				  t = renderGridByNode(node,nn,function(cv){
				  	  if(Bat.gvs.wf_user.indexOf('avens_')==0)
					  	cv.req.map.psMap.map.hql+=" and A.assignmentId.resourceUsername ='avens_admin' order by B.startTime desc";
					  else
					  	cv.req.map.psMap.map.hql+=" and A.assignmentId.resourceUsername ='"+Bat.gvs.wf_user+"' order by B.startTime desc";
					  return cv;
				  });
			else if(node.text=='已办')
				  t = renderGridByNode(node,nn,function(cv){
					  cv.req.map.psMap.map.hql="from avens.persistence.hibernate.Activity A, dao.hb.RelAvensCe B, AvensResource C, avens.formsado.dpm_ce.dpm_ce_ado D where D.wfWorkItem=A.id and B.wfworkitem=A.id and C.username=A.submitPerformer and A.submitPerformer='"
					  +Bat.gvs.wf_user+"' order by A.submitTime desc";
					  return cv;
				  });
			else if(node.text=='全部已办')
				  t = renderGridByNode(node,nn,function(cv){
					  cv.req.map.psMap.map.hql="from avens.persistence.hibernate.Activity A, dao.hb.RelAvensCe B, AvensResource C, avens.formsado.dpm_ce.dpm_ce_ado D  where D.wfWorkItem=A.id and B.wfworkitem=A.id and C.username=A.submitPerformer  order by A.submitTime desc";
					  return cv;
				  });
			else	
				t = renderGridByNode(node,nn);
		}
	});
	//tree.expandAll();
	return tree;
},
initDatabase:function(id,title,iconCls){
	var root = new Ext.tree.TreeNode({
		text: INFO('Database'), 
		allowDrag:false,
		allowDrop:true
	});
	var nn={		
		  "OBJ_VIEW":{fv:'对象查看',fn:'vn',ns:Bat.gvs.ovs_fvcn}
	};
	if(Bat.gvs.ovs_funcs['SYS_WEBSITE'])
		nn['OBJ_MANAGE']={fv:'对象维护',fn:'vn',ns:Bat.gvs.ovs_fvcn};
	else
		nn['OBJ_MANAGE']={fv:'对象维护',fn:'vn',ns:Bat.gvs.ovs_fvdraft};
	if(Bat.gvs.wf_role.indexOf('dpm_ce_fyr')!=-1)
		nn['OBJ_TRANSLATE']={fv:'对象翻译',fn:'vn',ns:Bat.gvs.ovs_fvcn};
	if(Bat.gvs.ovs_funcs['SYS_WEBSITE']){
		nn['OBJ_PUBLISH']={fv:'对象发布',fn:'vn',ns:Bat.gvs.ovs_fvcn};
		nn['OBJ_PUBLISH_NEVER']={fv:'对象未发布',fn:'vn',ns:Bat.gvs.ovs_fvcen};
	}

	for(var x in nn){
	  if((typeof nn[x])=='string'){
	  	root.appendChild(
			new Ext.tree.TreeNode({text:INFO(x), vn:x,allowDrag:false,allowDrop:false})); 
	  }else{
	  	buildNode(root,nn[x]);
	  }
	} 	
   var tree = new Ext.tree.TreePanel( {
		id:id,
		title:title,
		iconCls:iconCls,
		root:root,
		animate:true, 
		enableDD:true,
		containerScroll: true,
		ddGroup: 'databaseDD',
		rootVisible:true
	});
	tree.on('click',function(node,e){
		var pn = node.parentNode;
		if(!pn) return false;
		if(pn.fv=='对象未发布' && (node.vn=='dao.hb.Lemma'||node.vn=='dao.hb.Contribution')){
			outputEx({message:'该对象联合查询存在性能问题，<br>请使用"批量发布"功能'},"抱歉此功能无法使用");
			return false;
		}
		var t = renderGridByNode(node,nn,function(cv){
			var btns_hide;
			var btns = cv.grid.btns;
			if(pn.fv=='对象未发布'){
				var rm = cv.req.map.psMap.map;
				var cn = rm.cns[0];
				var kn = Bat.gvs.ovs[cn].key;
				if(rm.cns.length>1)
				  kn = "A."+kn;
				if(node.text.indexOf('[英文]')>-1)
				  cn=cn+"Uk";
				var pos = rm.hql.toLowerCase().indexOf('where');
				if(pos>0)
				  rm.hql = rm.hql.substring(0,pos+5)
				  +" "+kn+" not in (select idfield from RpArticle where tablename='"
					+cn+"') and "+rm.hql.substring(pos+6);
				else
				  rm.hql += " where "+kn
						+" not in (select idfield from RpArticle where tablename='"
						+cn+"')";
				btns[btns.length]={
					text: '发布',
		   			iconCls: 'htm',
					handler : function(btn){
						CC.showPubObj(btn);
					}
				}
			}
			if(pn.fv=='对象发布'){
				btns[btns.length]={
					text: '发布',
		   			iconCls: 'htm',
					handler : function(btn){
						CC.showPubObj(btn);
					}
				}
			}
			if(pn.fv=='对象翻译'){
				btns[btns.length]={
					text: '翻译',
		   			iconCls: 'import',
					handler : function(btn){
						var t=btn.ui;
		    	 		var sels=t.grid.getSelections();
			    		if(!sels || sels.length==0) return;	
			    		t.grid.getSelectionModel().clearSelections();   
						Ext.MessageBox.wait('正在提交，请稍候...'); 
						var req =Bat.clone( t.req);
						var rm = req.map.psMap.map;
						rm.packageId='dpm_ce';
						rm.processDefinitionId='dpm_ce';
						rm.method='Y';
						rm.objs=[sels[0].obj];
						//服务暂时不能处理多个草稿提交
						/*for(var i=0; i<sels.length; i++){
							rm.objs[rm.objs.length]=sels[i].obj;
						}*/
						req.map.SN = 'AvensHandle';
						var reqs = [req];
					  	jsonrpc.BH.handle(function(data,ex){
			        		if(outputEx(ex,'提交工作单异常'))
			        			return;
					  		t.load();
					  		Ext.MessageBox.hide();
					  	},reqs);
					}
				}
			}
			//if(pn.fv=='对象维护'||pn.fv=='网站管理')
			if(pn.fv!='对象查看' && pn.fv!='对象翻译'){
				btns_hide= cv.grid.hidebtns_objmode;
				for(var i=0;i<btns.length; i++){
					if(btns[i]=='增加'){
						btns_hide[btns_hide.length]=i;
						break;
					}
				}
			}
			//if(pn.fv=='对象查看'||pn.fv=='对象翻译'){
			else{
				btns_hide= cv.grid.hidebtns_objview;
				//修改"打开"按钮
				for(var i=0; i<btns.length; i++){
					if(btns[i]=='打开'){
						btns[i] = '查看';
						break;
					}
				}
			}
			if(!btns_hide)
				return cv;
			for(var i=0; i<btns_hide.length; i++){
				btns[btns_hide[i]]=null;
			}
			return cv;
		});
		
	});
	//tree.expandAll();
	return tree;
},
dowithLogin:function(data,user){
	var wf_role = data[0][0];
	var wf_funcs;
	if(user.indexOf('avens_')==0){
	  wf_role='ps.user';
	  wf_funcs=['SYS_PERMISSION'];
	}else{
		wf_funcs = data[0][2].split(";");
	}
	if(wf_role=='')
		return;
	Bat.gvs.wf_role=wf_role;

	var wf_objs = data[0][1].split(";");
	for(var i=0; i<wf_objs.length; i++){  
		var x = wf_objs[i];
		if(Bat.gvs.ovs[x])
		  Bat.gvs.ovs_fvdraft[Bat.gvs.ovs_fvdraft.length]={fv:Bat.gvs.ovs[x].cn,vn:x};
	}
	for(var i=0; i<wf_funcs.length; i++){
		var x = wf_funcs[i];
		Bat.gvs.ovs_funcs[x]=true;
	}
    Bat.gvs.wf_user = user;
    Bat.gvs.wf_un = Bat.gvs.wf_userName+'['+user+']';
},
initPrjTree:function(id,title,iconCls){
	var root = new Ext.tree.TreeNode({
		text: '项目管理', 
		allowDrag:false,
		allowDrop:true
	});
	var nn={
		"项目":'dao.hb.PrjProject',
		"项目里程碑":'dao.hb.PrjMilestones',
		"会议记录":"dao.hb.PrjMinutes"
	};
	for(var x in nn){
	  if((typeof nn[x])=='string'){
	  	root.appendChild(
			new Ext.tree.TreeNode({text:INFO(x), vn:nn[x],allowDrag:false,allowDrop:false})); 
	  }else{
	  	if(Bat.gvs.ovs_funcs[x])
	  	  buildNode(root,nn[x]);
	  }
	} 	
   var tree = new Ext.tree.TreePanel( {
		id:id,
		title:title,
		iconCls:iconCls,
		root:root,
		animate:true, 
		enableDD:true,
		containerScroll: true,
		ddGroup: 'ProjectDD',
		rootVisible:true
	});
	tree.on('click',function(node,e){
		var t = renderGridByNode(node,nn,function(cv){
			return cv;
		});
		
	});
	return tree;
},   
initSysTree:function(id,title,iconCls){
	var root = new Ext.tree.TreeNode({
		text: '系统管理', 
		allowDrag:false,
		allowDrop:true
	});
	var nn={		
		"SYS_ADMIN":{fv:'系统维护',fn:'vn',ns:[
			{fv:'对象批量发布',vn:'dao.hb.RpArticle'},
			{fv:'对象批量打标',vn:'dao.hb.RpMarkingResult'},
			{fv:'控制变量',vn:'dao.hb.CeSysVar'},
			{fv:'系统状态',vn:'dao.hb.CeModule'},
			{fv:'系统日志',vn:'dao.hb.CeModuleLog'},
			{fv:'网站日志统计',vn:'dao.hb.StaWeblog'},
			{fv:'稿酬因子',vn:'dao.hb.BasePayfactor'},
			{fv:'权限管理',vn:'dao.hb.AvensResource'}]},
		"SYS_PERMISSION":{fv:'用户权限',vn:'dao.hb.AvensResource'},
		"SYS_WEBSITE":{fv:'网站管理',fn:'vn',ns:[
			{fv:'频道模板和前言',vn:'dpm.admin.site'},
			{fv:'网站评论管理',vn:'dao.hb.CeCommentOut'},
			{fv:'网站用户管理',vn:'dao.hb.CeUserOut'},
			{fv:'机构介绍',vn:'dao.hb.AvensOrg'},
			{fv:'外单位人员',vn:'Base_author22'},
			{fv:'调查问卷',fn:'vn',ns:[
		  			{fv:'问卷管理',vn:'dao.hb.CeQuestionnaire'},
		  			{fv:'问题管理',vn:'dao.hb.CeQuestion'},
		  			{fv:'选项管理',vn:'dao.hb.CeItems'}	
		  			]
				},
			{fv:'网站链接',vn:'dao.hb.CeLink'},
			{fv:'网站特辑',vn:'dao.hb.CeAlbum'},
			{fv:'邮件发送',vn:'dao.hb.MailSend'}]},
		"SYS_CC":{fv:'基表管理',fn:'vn',ns:[
			{fv:'内容采编基表',fn:'vn',ns:[
		  {fv:'书籍形式分类基表',vn:'Base_bookclass_format12'}, 		  
		  {fv:'文物保护分类基表',vn:'Base_protectclass17'},
		  {fv:'学科分类基表',vn:'Base_subject20'},
		  {fv:'专题类型基表',vn:'Base_culturetype24'},
		  {fv:'礼品分类基表',vn:'Base_presentclass16'},
		  {fv:'古建区域基表',vn:'Base_buildingarea3'},
		  {fv:'古建分类基表',vn:'Base_buildingclass4'},
		  {fv:'年代',vn:'Base_era7'},
		  {fv:'对象类型基表',vn:'Base_objtype13'},		   
		  {fv:'人物分类基表',vn:'Base_person14'},		  
		  {fv:'文物分类',vn:'Base_relicclass18'},		  
		  {fv:'语种基表',vn:'Base_booklanguage2'}, //图书语种类型基表
		  {fv:'职称基表',vn:'Base_title21'},		  
		  {fv:'摄影作者表',vn:'Base_photographer23'},
		  {fv:'文稿分类基表',vn:'Base_doctype30'},
		  {fv:'展览分类基表',vn:'Base_Exhibitiontype'},
		  {fv:'外单位人员',vn:'Base_author22'}]},
		  {fv:'网站基表',fn:'vn',ns:[
		  {fv:'站点结构基表',vn:'Base_websiteclasscn27'},
		  {fv:'附件用途基表',vn:'Base_attachtype'},
		  {fv:'国籍居住地基表',vn:'Base_Nationlity'},
		  {fv:'民族基表',vn:'BaseFolk'},
		  {fv:'学历基表',vn:'BaseEducation'},
		  {fv:'语种基表',vn:'BaseLanguage'},
		  {fv:'网站栏目基表',vn:'BaseReltitle'}
		  ]},
		  {fv:'生僻字管理',vn:'Base_allograph'}
		  ]},
		"SYS_PAY":{fv:'稿酬管理',fn:'vn',ns:[
			{fv:'稿酬确认',vn:'dao.hb.CcPay'},
		  	{fv:'稿酬发放',vn:'dao.hb.CcPayff'},
		  	{fv:'稿酬发放历史',vn:'dao.hb.CcPayHistory'},
		  	{fv:'老系统稿酬',fn:'vn',ns:[
		  		{fv:'文稿正文',vn:'dao.hb.ogcdocDes'},
		  		{fv:'文稿审查',vn:'dao.hb.ogcdocShencha'},
		  		{fv:'文稿终审',vn:'dao.hb.ogcdocZhongshen'},
		  		{fv:'文稿翻译',vn:'dao.hb.ogcdocFanyi'},
		  		{fv:'文稿翻译审查',vn:'dao.hb.ogcdocFanyishecha'},
		  		{fv:'论文',vn:'dao.hb.ogcThesis'},
		  		{fv:'论文专著目录',vn:'dao.hb.ogcLunwenzhuanzhumulu'},
		  		{fv:'影像',vn:'dao.hb.ogcImage'},
		  		{fv:'词条',vn:'dao.hb.ogcLemma'},
		  		{fv:'礼品',vn:'dao.hb.ogcPresent'},
		  		{fv:'贺卡',vn:'dao.hb.ogcCard'}
		  	]}]},	  
		"SYS_STAT_WORK":{fv:'工作量统计',fn:'vn',ns:[
			{fv:'内容采编',vn:'wf_history'},
		  	{fv:'内容发布',vn:'dao.hb.RpArticle2'}]}	  
	};
	for(var x in nn){
	  if((typeof nn[x])=='string'){
	  	root.appendChild(
			new Ext.tree.TreeNode({text:INFO(x), vn:x,allowDrag:false,allowDrop:false})); 
	  }else{
	  	if(Bat.gvs.ovs_funcs[x])
	  	  buildNode(root,nn[x]);
	  }
	} 	
   var tree = new Ext.tree.TreePanel( {
		id:id,
		title:title,
		iconCls:iconCls,
		root:root,
		animate:true, 
		enableDD:true,
		containerScroll: true,
		ddGroup: 'databaseDD',
		rootVisible:true
	});
	tree.on('click',function(node,e){
		var pn = node.parentNode;
		if(!pn) return false;
		var t = renderGridByNode(node,nn,function(cv){
			return cv;
		});
		
	});
	//tree.expandAll();
	return tree;
},   //打标  查看
   showMarkingDetail:function (req,data){  	
  	var pss1 = req.map.psMap.map.pss[0];//['id','lemmaName','description']
  	var pss2 = req.map.psMap.map.pss[1];
  	var o = data[0];
  	var p1value1="";
  	var p1value2="";
  	var p1value3="";
  	var p2value1="";
  	var p2value2="";
  	var p2value3="";
	for(var i=0,len=o.length; i<len; i++){
		if(o[i].action=='R' || o[i].action=='D'	)
		  continue;
		var imap = o[i].items.map;
		p1value1 = imap["A."+pss1[0]];
		p1value2 = imap["A."+pss1[1]];
		p1value3 = imap["A."+pss1[2]];
		p2value1 = imap["B."+pss2[0]];
		p2value2 = imap["B."+pss2[1]];
		p2value3 = imap["B."+pss2[2]];		
		//var aidval = imap["A.id"];
		//for (x in imap){
			//pvalue1 = imap[x];
		//}		
		break;		
	}
	//clob[p1value3] 加颜色[]
    if (p1value3){
		var ipos=p1value3.indexOf(p2value2); // 词条
		if (ipos >= 0){  
			var str1=p1value3.substring(0,ipos);
			var str2=p1value3.substring(ipos + p2value2.length);
			//me.clobdata = str1 + "<font color=\"#FF0000\">"+itemvalue2+"</font>"+str2;
			p1value3 = str1 + "◆["+p2value2+"]◆"+str2;
		}
    }					
   if(!CC.MarkingDetailDlg){ // lazy initialize the dialog and only create it once
    var fs = new Ext.FormPanel({
        frame: true,
        labelAlign: 'top',
        labelWidth: 120,
        width: 450,
        height:520,
        //html:me.clobdata,
     items: [{
        layout:'column',
		xtype: 'panel',
		items:[{
        columnWidth:1,
        //layout: 'form',
        items: new Ext.form.FieldSet({
        		//body:me.clobdata,
                //title: INFO('Source'),
                title: '',
                autoHeight: true,
                defaults: {width: 400},
                defaultType: 'textfield',
        items: [
	        new Ext.form.TextField({
	            fieldLabel: '原始表记录的id',
	            name: 'Mfield_id',
	            id: 'Mfield_id',
	            width:350,
	            value: p1value1,
	            readOnly:true
	        })	        
			,
			new Ext.form.TextField({
	            fieldLabel: '原始表记录的名称',
	            name: 'Mfield_objname',
	            id: 'Mfield_objname',
	            value: p1value2,
	            readOnly:true
	        }),
			new Ext.form.TextArea({
	            fieldLabel: '原始表记录的描述',
	            name: 'Mfield_description',
	            id: 'Mfield_description',
	            width:350,
	            height:120,
	            value: p1value3,
	            readOnly:true
	        }),
	        new Ext.form.TextField({
	            fieldLabel: '词条',
	            name: 'Mfield_lemma',
	            id: 'Mfield_lemma',
	            value: p2value2,
	            readOnly:true
	        }),
	        new Ext.form.TextArea({
	            fieldLabel: '词条的描述',
	            name: 'Mlemma_description',
	            id: 'Mlemma_description',
	            width:350,
	            height:80,
	            value: p2value3,
	            readOnly:true
	        })
            ]
         })}

         ]}]
    });
    var dlg2  = new Ext.Window({          //打开打标操作窗体
    		closeAction:'hide',
            title: INFO('打标结果'),
            layout:'fit',
            width:500,
            height:520,
            plain: true,
            items:fs,
            buttons: [{
                text:'关闭',
                handler: function(){
                	CC.MarkingDetailDlg.hide();
                }
            }]
     });
     CC.MarkingDetailDlg=dlg2 ;
    }else{
      //todo
      document.getElementById("Mfield_id").value=p1value1;
      document.getElementById("Mfield_objname").value=p1value2;
      document.getElementById("Mfield_description").value=p1value3;
      
      document.getElementById("Mfield_lemma").value=p2value2;
      document.getElementById("Mlemma_description").value=p2value3;      
    }    
    CC.MarkingDetailDlg.show();		
	}
}

}();

  Ext.onReady(function(){
		jsonrpc = new JSONRpcClient("/cc/JSON-RPC");	
		jsonrpc_task = new JSONRpcClient("/cc/JSON_TASK");	
  		Bat.UI.ROWCOUT = document.body.clientHeight>600?30:20;
  		document.oncontextmenu=function(){
  			return false;
  		}
		Ext.form.Field.prototype.msgTarget = 'side';
		Ext.QuickTips.init();
		//20100401
        Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
        var login_f=function(ps,succ){
    	  var req={"map":{"psMap":{map:ps,"javaClass":"java.util.HashMap"},"SN":"AvensHandle"},"javaClass":"java.util.HashMap"};
    	  jsonrpc.BH.handle(function(data,ex){
	   		if(outputEx(ex,'用户登录异常'))
	   			return;
    	  	CC.dowithLogin(data,ps.user);
    		succ();
        	//loginwin.hide();            	
        	//succfunc();            		
    	  },[req]);            	
        }
        var loginsucc=function(){
        var its,tabs;        
        if(Bat.gvs.wf_role!=''){
          CC.welcome_text = new Ext.Toolbar.TextItem('<b>'+Bat.gvs.wf_userName
          +'</b>&nbsp;&nbsp;&lt;'+(new Date()).toLocaleString()+'登录&gt;');
          if(bCCDebug){
	          its=[
	            CC.initWfTree('tree_wf',INFO('Workflow'),'workflow'),
	            CC.initDatabase('tree_database',INFO('Database'),'database'),
	            CC.initSysTree('tree_sys','系统管理','sysadmin')
	          ];
	          if(Bat.gvs.ovs_funcs['SYS_PRJ'])
	         	its[its.length]=CC.initPrjTree('tree_prj','项目管理','prj_admin');
          }
	      else
	      	its=[CC.initDatabase('tree_database',INFO('Database'),'database')];
          	//tabs=[];
        }
        var tbar = new Ext.Toolbar(CC.initToolbar());
       var tabPanel=new Ext.TabPanel({
        	tabs:{},
        	show_tabs:{},
            region:'center',
            id:'center',
            enableTabScroll:true,//wjh
            defaults: {autoScroll:true},//wjh                    
            deferredRender:false,
            listeners:{"contextmenu":function(tabs,tab,e){
              tabs.tabmenu=tab;
              var menu = tabPanel.cmenu;
              if(!menu){
				menu=new Ext.menu.Menu([{
				text:"关闭其他页",
				handler:function(){
					tabs.setActiveTab(tabs.tabmenu);
					//循环遍历
					tabs.items.each(function(item){
					if(item!=tabs.tabmenu){
				        tabs.hideTabStripItem(item.hide());
				        item.bHide=true;
					}
					});
				 }
				},{
				text:"关闭所有页",
				handler:function(){
					//循环遍历
					tabs.items.each(function(item){
				        tabs.hideTabStripItem(item.hide());
				        item.bHide=true;
					});
				 }
				}]);
				tabPanel.cmenu=menu;
              }
				//显示在当前位置
				menu.showAt(e.getPoint()); 
			  }
            }
        });
       tabPanel.on('beforeremove', function(tabs, tab) {
	        tabs.hideTabStripItem(tab.hide());
	        tab.bHide=true;
	        var tids=[];
	        for(x in tabs.tabs)
	          tids[tids.length]=x;
	        if(tab==tabs.getActiveTab()){
	        	for(var i=tids.length-1; i>=0; i--){
	        		var tc = tabs.getItem(tids[i]);
	        		if(!tc.bHide){
	        			tabs.setActiveTab(tc);
	        			break;
	        		}
	        	}
	        }
	        return false;
		});	

        viewport = new Ext.Viewport({
            layout:'border',            
            items:[
            	tbar,
                   {
                   	//iconCls:'nav',
                    region:'west',
                    id:'west-panel',
                    title:'我的工具箱',
                    split:true,
                    width: 200,
                    minSize: 175,
                    maxSize: 400,
                    collapsible: true,
                    margins:'0 0 0 5',
                    layout:'accordion',
                    layoutConfig:{
                        animate:true
                    },
                    items: its
                },tabPanel
                
             ]
        });
        CC.tbar = tbar;
		tabPanel.add({
			bodyStyle:'padding:10px;font-size:12px;',
            title: '版本更新说明',
            iconCls: 'tabs',
            contentEl: 'tabs_about',
            closable:true
        }).show();
         //Bat.Message.onSpan();
        Cookies.setAge('JSESSIONID',1);
        };
        
        var dologin = function(){
        bUM = decodeURIComponent(window.location.search);
        if(bUM=='?cas=true'){
	        var cookie_user;
	        for(var i=0; i<5; i++){
	           cookie_user = readCnCookie('COOKIE_USER');
	           if(cookie_user)
	             break;
	        }
			if(cookie_user){
	           // Bat.gvs.wf_user = cookie_user;
				//Bat.gvs.wf_role=readCnCookie('COOKIE_ROLE');
	            Bat.gvs.wf_userName= readCnCookie('COOKIE_UN');
	            Bat.gvs.wf_un = Bat.gvs.wf_userName+'['+cookie_user+']';
	            CC.dowithLogin([[readCnCookie('COOKIE_ROLE'),
	            readCnCookie('COOKIE_OBJ'),
	            readCnCookie('COOKIE_FUNC')]],cookie_user);
	            loginsucc();
			}else{
				Cookies.clear('COOKIE_OBJ');
				Cookies.clear('COOKIE_FUNC');
				Cookies.clear('COOKIE_USER');
				Cookies.clear('COOKIE_ROLE');
				Cookies.clear('COOKIE_UN');
				document.location='/cc/servlet/authenticate?';
			}
        }else{
        	if(bUM.indexOf('?iam')==0){
        	    CC.login(loginsucc,login_f,bUM);
        	}
        	else if(bUM=='?zmhm'){
        	    CC.login(loginsucc,login_f);
        	}
        	else if(bUM=='?hhdd'){
        		Bat.gvs.wf_user = 'dev';
				Bat.gvs.wf_role='dev';
	            Bat.gvs.wf_userName= '开发人员';
	            Bat.gvs.wf_un = Bat.gvs.wf_userName+'['+cookie_user+']';
	           // bCCDebug=true;
	            CC.dowithLogin([['ps.user','','SYS_ADMIN']],'dev');
        		loginsucc();
        	}
        	else	{
        		Ext.MessageBox.alert('登录说明', '内容采编已纳入统一用户认证，系统将引导您登录。', function(btn){
        		  document.location='/cc/servlet/authenticate?';
        		});
        		
        	}
        }
        }
        setTimeout(dologin,200); 
    });

     //打标 wjh 查看 结束